package org.colcon.web.client.ui.deprecated;

import org.colcon.web.client.Collective_Congress;
import org.colcon.web.client.ui.ClickablePanel;
import org.colcon.web.model.User;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;

public class AccountLink extends ClickablePanel
{
	public AccountLink(Collective_Congress client)
	{
		super(client, "user-item", client.getUser().getId());
	}
	
	public void click()
	{
		getBodyPanel().clear();
		getBodyPanel().add(new Label("Loading..."));
		
		getService().getUser(getClient().getUser().getId(), new AsyncCallback<User>()
		{
			public void onFailure(Throwable caught)
			{
				System.err.println("Failed to refresh user " + getClient().getUser().getId());
				getClient().logout();
				getClient().refresh();
			}
			
			public void onSuccess(User user)
			{
				getClient().login(user);
				getBodyPanel().clear();
				UserInfoPanel panel = new UserInfoPanel(getClient(), getClient().getUser());
				getBodyPanel().add(panel);
			}
		});
	}
}
